package com.huanying.http;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class GetXfgc {
	public void get() throws Exception{
		for(int j=1;j<=20;j++){
			Document doc = Jsoup.connect("http://www.xfgc.net.cn/info/baozhi/cid/22?p="+j+"/").get();
			Element table = doc.getElementsByAttributeValue("class", "recruitment-tb").get(1);
			Elements list_tr = table.getElementsByTag("tr");
			Element a;
			Element td;
			String url="";
		    String name="";
		    String phone="";
		    String price="";
		    String sql;
		    for(int i=0; i<list_tr.size(); i++){
		    	Elements list_td = list_tr.get(i).getElementsByTag("td");
		    	for(int k=0;k<list_td.size();k++){
		    		if(k==0){
		    			a = list_td.get(k).getElementsByTag("a").first();
		    			name = a.text().trim();
		    			url = a.attr("href");
		    		}
		    		if(k==1){
		    			td = list_td.get(k);
		    			phone = td.html();
		    		}
		    	}
		    	
		    	System.out.println(url);
		    	System.out.println(name);
		    	System.out.println(phone);
		    	sql = "insert into fang_apartment(url,name,phone,price) values ('"+url+"','"+name+"','"+phone+"','"+price+"')";
		    }
	    }
	}
	
	public String getPhone(Document doc) throws Exception{

	    return null;
	}
	
	public String getPrice(Document doc) throws Exception{

	    return null;
	}
	
	public String getShape(Document doc) throws Exception{

	    return null;
	}
	
	public static void main(String[] args) {
		GetXfgc g58 = new GetXfgc();
		try {
			g58.get(); 
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
